@extends('app')
@include('UEditor::head')
@section('content')
<ul class="nav nav-tabs">
    <li><a href="/admin/teaches/index">列表</a></li>
     <li class="active"><a href="#">新增</a></li>
</ul>
<form id="newsForm">
        <div class="description2">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属企业：</label>
                <div class="col-sm-9 col-xs-12">
                    <select name="company_id" class="form-control">
                        <option value="0">--请选择企业--</option>
                        @foreach($companys as $company)
                        <option value="{{ $company->id }}" @if(!empty($result)) @if($company->id == $result->company_id) selected @endif @endif>{{ $company->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章标题：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" class="form-control" name="name" id="name" placeholder="标题" value="@if(!empty($result)){{$result->name}}@endif">
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="from-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">封面图片：</label>
                <div class="col-sm-9 col-xs-12">
                    <div class="input-group ">
                    	<input type="file" name="thumburl" id="thumburl" value="" class="form-control" autocomplete="off">
                    </div>
                     <div id="imgbox" class="dustbin">
                     @if(!empty($result))
                        @if(count($result->attachment)>0)
        	              <img src='{{$result->attachment->url}}'  width='90' height='60'>
        	              <input type='hidden' name='thumb' value='{{$result->attachment->aid}}'>
        	           @endif
        	         @endif
                     </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group mt10">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程简介：</label>
                <div class="col-sm-9 col-xs-12">
                    <script id="description" name="description"  style="width:100%;margin:0 auto;height:100px;" type="text/plain">
                    </script>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        <div class="tools">
            @if(!empty($office))
            <div class="form-group" id="office">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程地址：</label>
                <div class="col-sm-9 col-xs-12">
                    <input id="officeid" name="officeid" type="hidden" value="{{ $office->id }}">
                    {{ url($office->url) }}
                </div>
                <div class="clearfix"></div>
            </div>
            @else
            <div class="form-group" id="office">
                @if(!empty($office->url))
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程地址：</label>
                <div class="col-sm-9 col-xs-12">
                    <input id="officeid" name="officeid" type="hidden" value="{{ $office->id }}">
                    {{ url($office->url) }}
                </div>
                @endif
                <div class="clearfix"></div>
            </div>
            @endif
            <div class="form-group" id="officeupload">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">上传教程：</label>
                <div class="col-sm-9 col-xs-12">
                    <input id="uploadoffice" name="uploadoffice" type="file" multiple="true">
                    <div id="imgbox"></div>
                    <div class="help-block" >请上传zip格式文件。</div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        
        <div class="content-layout end-layout">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">相关标签</label>
                <div class="col-sm-9 col-xs-12">
                    <div class="tagsinput-primary">
                        <input name="tagsinput" class="tagsinput" data-role="tagsinput" value="@if(!empty($newstag)) {{ $newstag }} @endif" />
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">教程价格：</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="number" name="price" class="form-control" value="@if(!empty($result)){{$result->price?$result->price:0}}@endif">
                    <div class="help-block" >为0则为免费课程。</div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">作者：</label>
                <div class="col-sm-3 col-xs-12">
                      <input type="text" class="form-control" name="author" id="author" placeholder="作者" value="@if(!empty($result)){{$result->author}}@endif">
                </div>
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">来源：</label>
                <div class="col-sm-3 col-xs-12">
                      <input type="text" class="form-control" name="from" id="from" placeholder="来源" value="@if(!empty($result)){{$result->from}}@endif">
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">首页推荐：</label>
                <div class="col-sm-3 col-xs-12">
                    <label class="radio-inline">
                      <input type="radio" name="is_recommond" value="1" @if(!empty($result)) @if($result->is_recommond == 1) checked @endif @endif> 是
                    </label>
                    <label class="radio-inline">
                      <input type="radio" name="is_recommond"value="0" @if(!empty($result)) @if($result->is_recommond == 0) checked @endif @else checked @endif> 否
                    </label>
                 </div>
                 <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="sort" class="form-control" value="@if(!empty($result)) {{$result->sort}} @else 0 @endif" />
                    <span class='help-block'>课程的排序，在前端列表展示的时候会用到，越大越靠前</span>
                </div>
                <div class="clearfix"></div>
            </div>
            <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
            <input type="hidden" name="teachesType" value="3">
            <input type="hidden" name="tcompanyid" value="@if(!empty($result)){{$result->id}}@endif">
            {!! csrf_field() !!}
            <div class="form-inline">
                <div class="form-group">
                  <button type="button" class="btn btn-info" id="publish_save" onclick="saveTeachesData('/admin/teaches/enterprise','newsForm',2)">
                    <i class="icon-ok bigger-110"></i>
                    Submit
                  </button>
                </div>
                <div class="form-group col-xs-offset-1">
                  <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                  </button>
                </div>
            </div>
        </div>
</form>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">添加文章标签</h4>
      </div>
      <div class="modal-body">
        <div class="addtags">
          <div class="tags">
            <div class="tags-label fl">已添加：</div>
            <div id="tagsdiv" class="fl"></div>
          </div>
          <form>
              <div class="col-xs-9 fl">
                  <div class="form-group">
                    <input type="text" class="form-control" id="addtags" name="addtags" placeholder="请输入标签（不超过7个字符）">
                  </div>
              </div>
              <div class="col-xs-3 fr">
                  <div class="form-group">
                    <input type="button" class="btn btn-default btn-block" id="savetags" name="savetags" value="添加" >
                  </div>
              </div>
              <div class="clear"></div>
              <div class="col-xs-12" id="errortips"></div>
          </form>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="submittags" data-dismiss="modal">确定</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>    

<script type="text/javascript">
<!--

var ue1 = UE.getEditor('description');
ue1.ready(function() {
	ue1.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.    
	ue1.setContent('@if(!empty($result)) {!! $result->description !!} @endif');
});

	$(function(){
		/***图片上传****/
		$("#uploadoffice").uploadify({
    	    'formData'     : {
    	        'fileField':'upfile',
    	        '_token':'{{ csrf_token() }}',
    	        'app':'teaches_company'
    	    },
    	    "width"           : 120,
    	    "height"          : 30,
    	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
    	    "fileObjName"     : "upfile",
    	    "buttonText"      : "上传教程",
    	    "uploader"        : '/admin/upload/ppt',
    	    'removeTimeout'	  : 1,
    	    'fileTypeExts'	  : '*.zip',
    	    'onUploadSuccess':function(file, data, response){
    	    	var data = eval('(' + data + ')');
    	        if (data.status == 'success') {
    	            var html="<label class=\"col-xs-12 col-sm-3 col-md-2 control-label\">教程地址：</label>"+
    	            		"<div class=\"col-sm-9 col-xs-12\"><input id=\"officeid\" name=\"officeid\" type=\"hidden\" value='"+data.id+"' >"+data.url+"</div><div class=\"clearfix\"></div>";
    	            $('#office').html(html);
    	        }else{
    	            alert(data.msg);
    	            return false;
    	        }
    
    	    }
    
    	});
    	$("#thumburl").uploadify({
    	    'formData'     : {
    	        'fileField':'upfile',
    	        '_token':'{{ csrf_token() }}',
    	        'app':'teaches'
    	    },
    	    "width"           : 120,
    	    "height"          : 30,
    	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
    	    "fileObjName"     : "upfile",
    	    "buttonText"      : "上传图片",
    	    "uploader"        : '/admin/upload/uploadimg',
    	    'removeTimeout'	  : 1,
    	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
    	    'onUploadSuccess':function(file, data, response){
    	    	var data = eval('(' + data + ')');
    	        if (data.status == 'success') {
    
    	        	var html="<div style='width:90px; height:60px;float:left;'>"
    	            	+"<img src='"+data.attach+"' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
    	            	+"</div>"
    	            $('#imgbox').html(html);
    	        }else{
    	            alert(data.msg);
    	            return false;
    	        }
    
    	    }
    
    	});
	});

//-->
</script>
@endsection
